/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entity;

import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.Lob;
import javax.persistence.OneToOne;
import type.RefundRequestStatus;

/**
 *
 * @author wei
 */
@Entity(name="RefundRequest")
public class RefundRequestEntity extends DataObjectEntity implements Serializable {
    private double amount;
    private RefundRequestStatus status;
    @Lob
    private String note;
    
    @OneToOne
    private SalesOrderEntity salesOrder;
    @OneToOne(mappedBy="refundRequest")
    private RefundEntity refund;

    public RefundRequestEntity() {
        super();
    }

    public double getAmount() {
        return amount;
    }

    public void setAmount(double amount) {
        this.amount = amount;
    }

    public SalesOrderEntity getSalesOrder() {
        return salesOrder;
    }

    public void setSalesOrder(SalesOrderEntity salesOrder) {
        this.salesOrder = salesOrder;
    }

    public RefundRequestStatus getStatus() {
        return status;
    }

    public void setStatus(RefundRequestStatus status) {
        this.status = status;
    }

    public RefundEntity getRefund() {
        return refund;
    }

    public void setRefund(RefundEntity refund) {
        this.refund = refund;
    }

    public String getNote() {
        return note;
    }

    public void setNote(String note) {
        this.note = note;
    }
    
    public boolean hasRefund(){
        return refund!=null;
    }
    
    public boolean refundRequestApproved(){
        return hasRefund() && status==RefundRequestStatus.approved;
    }
    
    @Override
    public String childToString() {
        return "RefundRequestEntity{" + "amount=" + amount + ", status=" + status + ", salesOrder=" + salesOrder + ", refund=" + refund + '}';
    }
    
}
